import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

const double _kPickerItemHeight = 44.0;

class MyPickerWidget extends StatelessWidget {
  final List<String> titles;
  final int initialIndex;
  final ValueChanged<int> valueChanged;

  MyPickerWidget({
    this.titles,
    this.initialIndex = 0,
    this.valueChanged,
  });

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: const TextStyle(
        color: CupertinoColors.black,
        fontSize: 22.0,
      ),
      child: SafeArea(
        top: false,
        child: CupertinoPicker.builder(
          scrollController:
              FixedExtentScrollController(initialItem: initialIndex),
          itemExtent: _kPickerItemHeight,
          onSelectedItemChanged: valueChanged,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              height: _kPickerItemHeight,
              child: Center(
                child: Text(titles[index]),
              ),
            );
          },
          childCount: titles.length,
          backgroundColor: Colors.white,
        ),
      ),
    );
  }
}
